package problemLCR187;

import java.util.ArrayList;
import java.util.List;

//LCR187.破冰游戏
//https://leetcode.cn/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/?envType=problem-list-v2&envId=recursion

class Solution {
    public int iceBreakingGame(int num, int target) {
        List<Integer> list = new ArrayList<>();
        for(int i = 0; i<num; i++) list.add(i);
        int k = target, t = 0;
        while(list.size() > 1) {
            int index = (t + k - 1) % list.size();
            t = index;
            list.remove(index);
        }
        return list.get(0);
    }
}